package org.yxj.videolibrary.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;


/**
 * 播放错误view
 *
 * @author on 2022/9/9
 */
public class PlayErrorView extends FrameLayout {


    private TextView textView ;


    public PlayErrorView( Context context) {
        this(context,null);
    }


    public PlayErrorView( Context context,  AttributeSet attrs) {
        this(context, attrs,0);
    }


    /**
     * @param context
     * @param attrs
     * @param defStyleAttr
     */
    public PlayErrorView( Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setBackground(bg());
        textView.setTextColor(Color.GREEN);
        textView.setPadding(25,25,25,25);
        addView(textView);
    }



    /**
     * @param error
     */
    public void setData(String error){
        if (!TextUtils.isEmpty(error)){
            setVisibility(VISIBLE);
            textView.setText(error);
        }else {
            setVisibility(GONE);
        }
    }


    /**
     * @return
     */
    public GradientDrawable bg(){
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setColor(Color.GRAY);
        gradientDrawable.setCornerRadius(30);
        return gradientDrawable;
    }
}
